<template>
  <view class="page-content">
    <u-loading-page :loading="loading" bg-color="#e8e8e8"></u-loading-page>
    <u--form
      labelWidth="auto"
      labelAlign="left"
      labelPosition="left"
      :model="detailform"
      :rules="rules"
      ref="form1"
    >
      <u-form-item label="服务名称" prop="muName" borderBottom ref="item1">
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.muName"
        ></u--text>
      </u-form-item>

      <u-form-item label="服务类型" prop="serverType" borderBottom ref="item1">
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.serverType"
        ></u--text>
      </u-form-item>

      <u-form-item
        label="服务说明"
        prop="serverExplain"
        borderBottom
        ref="item1"
      >
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.serverExplain"
        ></u--text>
      </u-form-item>

      <u-form-item label="推荐程度" prop="recommend" borderBottom ref="item1">
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.recommend"
        ></u--text>
      </u-form-item>

      <!-- <u-form-item label="服务佣金" prop="serverFee" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.serverFee"></u--text>
			</u-form-item> -->

      <u-form-item label="备注" prop="remark" borderBottom ref="item1">
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.remark"
        ></u--text>
      </u-form-item>

      <u-form-item label="完成情况" prop="comStatus" borderBottom ref="item1">
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.comStatus"
        ></u--text>
      </u-form-item>

      <u-form-item label="完成时间" prop="comTime" borderBottom ref="item1">
        <u--text
          bold
          margin="5px"
          align="right"
          :text="detailform.comTime"
        ></u--text>
      </u-form-item>

      <u-form-item label="服务前照片" prop="beforeImg" borderBottom ref="item1">
        <imageUpload readonly v-model="detailform.beforeImg" />
      </u-form-item>

      <u-form-item label="服务后照片" prop="afterImg" borderBottom ref="item1">
        <imageUpload readonly v-model="detailform.afterImg" />
      </u-form-item>
    </u--form>

    <u-row customStyle="margin:10px">
      <u-col span="12">
        <u-button
          class="custom-style"
          @click="handel_edit_click"
          type="success"
          size="small"
          >编辑
        </u-button>
      </u-col>
    </u-row>

    <!-- 	<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button v-if="detailform.prodType == '智能设备'" class="custom-style" @click="handel_history_click"
					size="small">历史数据查询
				</u-button>
			</u-col>
		</u-row> -->

    <!-- <u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_delete_click" :disabled="disabled_Delete" type="error"
					size="small">删除
				</u-button>
			</u-col>
		</u-row>
		<u-modal :show="show" :showCancelButton="true" :content="content" @confirm="handle_confirmDelete_click"
			@cancel="handle_confirmCancel_click">
		</u-modal> -->
  </view>
</template>

<script>
import { GetDatetime } from "@/utils/stringFormat.js";

import {
  listSlhgzresqjl,
  getSlhgzresqjl,
  delSlhgzresqjl,
  addSlhgzresqjl,
  updateSlhgzresqjl,
} from "@/api/elder/serviceApply.js";

import {
  listSlhgzfwwc,
  getSlhgzfwwc,
  delSlhgzfwwc,
  addSlhgzfwwc,
  updateSlhgzfwwc,
} from "@/api/elder/serviceApply_SMFW.js";

import {
  QueryDeviceInstallList,
  addDeviceInstall,
  updateDeviceInstall,
  getDeviceInstall,
  delDeviceInstall,
  QueryDeviceInstallHistory,
  QueryDeviceInstallDev,
} from "@/api/elder/DeviceInstall";
import imageUpload from "@/components/image-upload/multiple.vue";
//from "@/components/image-upload/single.vue";
import {
  transformPostBody,
  transformRequestURL,
} from "@/utils/requestParams.js";

export default {
  components: {
    imageUpload,
  },
  data() {
    return {
      id: null, //服务申请id号
      loading: false, //加载中
      show: false, //删除确认窗口
      content: "确认删除此条老人信息?",
      rules: {},
      queryParams: {
        pageNum: 1,
        pageSize: 150,
        taskId: null,
      },
      serviceApply: {
        searchValue: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        params: {},
        id: null,
        taskId: null,
        taskTypeCode: null,
        taskTypeName: null,
        begName: null,
        begTime: null,
        serverType: null,
        serverId: null,
        serverName: null,
        elderId: null,
        elderName: null,
        elderIdno: null,
        taskProvince: null,
        taskCity: null,
        taskDistrict: null,
        taskTown: null,
        taskVillage: null,
        taskStreet: null,
        taskRegisterAdd: null,
        taskLongitude: null,
        taskLatitude: null,
        planStartTime: null,
        planEndTime: null,
        startTime: null,
        endTime: null,
        status: null,
        taskDetail: null,
        isSelfSign: null,
        elderSign: null,
        approveName: null,
        approveResult: null,
        approveOpinion: null,
        star: null,
        appraise: null,
        realLongitude: null,
        realLatitude: null,
        attribute1: null,
        attribute2: null,
        attribute3: null,
        attribute4: null,
        attribute5: null,
        attribute6: null,
        attribute7: null,
        attribute8: null,
        attribute9: null,
        attribute10: null,
        attribute11: null,
        attribute12: null,
        attribute13: null,
        attribute14: null,
        attribute15: null,
        attribute16: null,
        attribute17: null,
        attribute18: null,
        attribute19: null,
        attribute20: null,
        attribute21: null,
        attribute22: null,
        attribute23: null,
        attribute24: null,
        attribute25: null,
        attribute26: null,
        attribute27: null,
        attribute28: null,
        attribute29: null,
        attribute30: null,
        attribute31: null,
        attribute32: null,
        defaultCommision: null,
        realCommision: null,
        commisionPay: null,
        prodToprice: null,
        prodRealpay: null,
        prodPay: null,
      },
      detailform: {
        searchValue: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        params: {},
        uuid: null,
        orderId: null,
        prodId: null,
        prodType: null,
        prodName: null,
        prodPic: null,
        prodSpeci: null,
        prodNum: null,
        price: null,
        totalPrice: null,
        isNece: null,
        remarke: null,
        devBelong: null,
        listBelong: null,
        elderUuid: null,
        taskId: null,
        isConfirm: null,
        comTime: null,
        beforeImg: null,
        afterImg: null,
      },
    };
  },
  onLoad: function (options) {
    console.log("改造项目明细：options", options);
    this.id = options.id;
    this.shenqingId = options.shenqingId;
    // //获取服务申请单条信息
    getSlhgzresqjl(this.shenqingId).then((response) => {
      console.log("获取服务申请单条信息", response);
      this.queryParams.taskId = response.data.taskId; //将老人id保存
      // this.serviceApply = response.data
      // this.getList();
    });
  },
  onShow() {
    this.getList(); //切换到此页面后刷新数据
  },
  computed: {
    disabled_Delete() {
      return !this.$auth.hasRole("admin");
    },
  },
  methods: {
    getList() {
      this.loading = true;
      getSlhgzfwwc(this.id).then((response) => {
        console.log("上门服务明细", response);
        this.loading = false;
        this.detailform = Object.assign({}, this.detailform, response.data);
      });
    },
    //跳转编辑页面
    handel_edit_click() {
      //检验是否已经签到
      listSlhgzresqjl({
        pageNum: 1,
        pageSize: 1000,
        taskId: this.queryParams.taskId,
      }).then((response) => {
        console.log("签到校验", response);
        this.serviceApply = response.rows[0];
        if (!this.serviceApply.startTime) {
          uni.$u.toast("请先签到");
        } else {
          this.$tab.navigateTo(
            "/pages/ShangMenFuWu/SMFW/edit?id=" +
              this.id +
              "&shenqingId=" +
              this.shenqingId
          );
        }
      });
    },
    //删除设备信息
    handel_delete_click() {
      this.show = true;
    },
    //确认删除
    handle_confirmDelete_click() {
      this.loading = true;
      delRTInfo([this.id])
        .then((response) => {
          uni.$u.toast("删除成功");
          this.loading = false;
          console.log("delRTInfo", response);
          this.show = false;
          this.$tab.navigateBack();
        })
        .catch((errors) => {
          console.log("errors", errors, this.id);
          uni.$u.toast("删除失败");
        });
    },

    //取消删除
    handle_confirmCancel_click() {
      this.show = false;
    },
    // //历史数据查询
    // handel_history_click() {
    // 	console.log('this.detailform', this.detailform)
    // 	//没法获取id进入，需要换成其他方法
    // 	// QueryDeviceInstallList({
    // 	// 		pageNum: 1,
    // 	// 		pageSize: 15
    // 	// 	},
    // 	// 	transformRequestURL({
    // 	// 		deviceNum: this.detailform.prodSn
    // 	// 	})
    // 	// ).then((response) => {
    // 	// 	console.log('handel_history_click', response)
    // 	// 	this.$tab.navigateTo('/pages/DeviceInstall/history?id=' + response.rows[0].id)
    // 	// });
    // },
  },
};
</script>

<style lang="scss">
page {
  background-color: white;
  display: flex;
  justify-content: center;
}

.page-content {
  width: 93%;
}

.custom-style {
  width: 80%;
  font-weight: bolder;
  font-size: 17px;
}
</style>